"use strict";
var chai = require("chai");
var GeoCom_1 = require('./../Model/TPS/GeoCom');
var q = require('q');
var co = require('co');
var serialport = require('serialport');
var expect = chai.expect;
var SurveyClass = require("./../Model/TPS/SurveyClass");
var portName = "";
before((done) => {
    portName.length === 0 && serialport.list(function (err, list) {
        var reg = /COM\d/;
        for (let item of list) {
            if (reg.test(item.comName)) {
                portName = item.comName;
                break;
            }
            else {
                console.log('nomatch');
            }
        }
        done();
    });
});
describe('全站仪', function () {
    this.timeout(10000);
    describe('#打开激光', function () {
        it('应该返回true', function () {
            return co(function* () {
                yield q.delay(500);
                var geocom = new GeoCom_1.GeoCom(portName);
                yield q.delay(500);
                var result = yield geocom.toggleLaser('1');
                geocom.close();
                return result;
            }).then(function (data) {
                expect(data).not.to.equal(null, '应该不返回null,打开激光操作失败,未能完成geocom指令');
                expect(data).to.be.equal(true);
            });
        });
    });
    describe('#打开ATR', function () {
        it('应该返回true', function () {
            return co(function* () {
                yield q.delay(500);
                var geocom = new GeoCom_1.GeoCom(portName);
                yield q.delay(500);
                var result = yield geocom.toggleATR('1');
                geocom.close();
                return result;
            }).then(function (data) {
                expect(data).not.to.equal(null, '应该不返回null,打开ATR操作失败,未能完成geocom指令');
                expect(data).to.be.equal(true);
            });
        });
    });
    describe('#打开RL', function () {
        it('应该设置全站仪为无棱镜测量,并且返回true', function () {
            return co(function* () {
                yield q.delay(500);
                var geocom = new GeoCom_1.GeoCom(portName);
                yield q.delay(500);
                var result = yield geocom.toggleMeaureMethod("RL");
                geocom.close();
                return result;
            }).then(function (data) {
                expect(data).not.to.equal(null, '应该不返回null,设置全站仪为无棱镜失败,未能完成geocom指令');
                expect(data).to.be.equal(true);
            });
        });
    });
    describe('#测距', function () {
        it('全站应该开始测量,并且返回坐标', function () {
            return co(function* () {
                yield q.delay(500);
                var geocom = new GeoCom_1.GeoCom(portName);
                yield q.delay(500);
                var result = yield geocom.measure();
                geocom.close();
                return result;
            }).then(function (data) {
                expect(data).not.to.equal(null, '应该不返回null,测量失败,未能完成geocom指令');
                expect(data.slope).to.be.a('number', '测量结果并不正确,应该为数字!!');
            });
        });
    });
});
describe('基础类功能测试', function () {
    describe('#Vector测试', function () {
        it('应该能够返回水平角', function () {
            var pt1 = new SurveyClass.SurveyPoint(0, 0, 0);
            var pt2 = new SurveyClass.SurveyPoint(0, -1, 0);
            var vector = new SurveyClass.SurveyVector(pt1, pt2);
            console.log(`\t水平角是${vector.horizontalAngle}`);
            expect(vector.horizontalAngle).to.be.a('number', '未能获取水平角');
        });
        it('应该能够返回垂直角', function () {
            var pt1 = new SurveyClass.SurveyPoint(0, 0, 0);
            var pt2 = new SurveyClass.SurveyPoint(0, 0, 1);
            var vector = new SurveyClass.SurveyVector(pt1, pt2);
            console.log(`\t垂直角是${vector.verticalAngle}`);
            expect(vector.verticalAngle).to.be.a('number', '未能获取垂直角');
        });
        it('应该能够返回水平距离', function () {
            var pt1 = new SurveyClass.SurveyPoint(0, 0, 0);
            var pt2 = new SurveyClass.SurveyPoint(0, -1, 1);
            var vector = new SurveyClass.SurveyVector(pt1, pt2);
            console.log(`\t水平距离是${vector.distance}`);
            expect(vector.distance).to.be.a('number', '未能获取水平距离');
        });
        it('应该能够返回斜距', function () {
            var pt1 = new SurveyClass.SurveyPoint(0, 0, 0);
            var pt2 = new SurveyClass.SurveyPoint(0, -1, 1);
            var vector = new SurveyClass.SurveyVector(pt1, pt2);
            console.log(`\t斜距是${vector.slope}`);
            expect(vector.slope).to.be.a('number', '未能获取斜距');
        });
    });
    describe('#TPS测试', function () {
        it('获取方位角测试', function () {
            var tps = new SurveyClass.TPS(100, 2000, 0);
            expect(tps.center.e).to.be.a('number', '不能能构建一个TPS全站仪类');
            tps.addPoint('pt1', new SurveyClass.SurveyPoint(100, 3000, 1));
            var pt1 = tps.getPoint('pt1');
            expect(pt1.name).to.be.equal('pt1');
            var hzhv = tps.convertToAzimuth('pt1');
            console.log(`\thv:${hzhv.hv},hz:${hzhv.hz}`);
            expect(hzhv.hz).to.be.a('number');
            expect(hzhv.hv).to.be.a('number');
        });
        it('展点测试,能把hv,hz,slope展成ENH', function () {
            var tps = new SurveyClass.TPS(100, 2000, 0);
            var coor = tps.convertToXYZ(Math.PI / 4, Math.PI * 60 / 180, 100);
            console.log(`\tE:${coor.e},N:${coor.h},H:${coor.n}`);
            expect(coor.e).to.be.a('number');
            expect(coor.h).to.be.a('number');
            expect(coor.n).to.be.a('number');
        });
    });
    describe('#深度拷贝测试', function () {
        it('应当能够正确的深度拷贝对象,修改一个对象不会影响另外一个', function () {
            var a = new SurveyClass.SurveyPoint(1, 2, 3);
            var b = Object.assign(new SurveyClass.SurveyPoint(), a);
            console.log(`\t拷贝后a.E=${a.e},b.E=${b.e}`);
            expect(a.e).to.be.eq(b.e);
            a.e = 100;
            console.log(`\t修改后a.E=${a.e},b.E=${b.e}`);
            expect(a.e).to.be.not.eq(b.e);
        });
    });
});
